package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * SpringAMQP配置类
 * 创建交换机、创建队列、将多个队列绑定到同一个交换机上
 */
@Configuration
public class FanoutConfig {

    //创建广播模式交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("itcast.fanout");
    }

    //创建队列 fanout.queue1
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }

    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }


    //将多个队列绑定到同一个交换机上
    @Bean
    public Binding binding1(Queue fanoutQueue1,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    @Bean
    public Binding binding2(Queue fanoutQueue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

    /**
     * 测试发送对象消息
     * 第一步：创建存放对象消息的队列
     */
    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue");
    }
}
